import request from "@/utils/request";

export function register(account, nickname, password) {
  const data = {
    account,
    nickname,
    password,
  };
  return request({
    url: "/register",
    method: "post",
    data,
  });
}

export function login(account, password) {
  const data = {
    account,
    password,
  };
  return request({
    url: "/login",
    method: "post",
    data,
  });
}

export function logout() {
  return request({
    url: "/logout",
    method: "post",
  });
}

export function getUserInfo() {
  return request({
    url: "/user/currentUser",
    method: "get",
  });
}

export function getArticles(query, page) {
  return request({
    url: "/article/getAllArticle",
    method: "get",
    params: {
      pageNo: page.pageNo,
      pageSize: page.pageSize,
      tagId: query.tagId,
      categoryId: query.categoryId,
      year: query.year,
      month: query.month,
    },
  });
}

export function getArticlesByTitle(parameter) {
  return request({
    url: "/article/getAllArticle",
    method: "get",
    params: parameter,
  });
}

export function getUpdateArtById(id) {
  return request({
    url: "/article/getUpdateArtById",
    method: "get",
    params: id,
  });
}

export function getArticleById(id) {
  return request({
    url: "/article/getArticleById",
    method: "get",
    params: id,
  });
}

export function getHotArtices() {
  return request({
    url: "/article/hot",
    method: "get",
  });
}

export function getNewArtices() {
  return request({
    url: "/article/new",
    method: "get",
  });
}

export function publishArticle(article) {
  return request({
    url: "/article/publishArticle",
    method: "post",
    data: article,
  });
}

export function getHotTags() {
  return request({
    url: "/tag/hot",
    method: "get",
  });
}

export function getAllCategory() {
  return request({
    url: "/category/getAllCategory",
    method: "get",
  });
}

export function getCategorysByName(parameter) {
  return request({
    url: "/category/getAllCategoryByName",
    method: "get",
    params: parameter,
  });
}

export function addCategory(parameter) {
  return request({
    url: "/category/addCategory",
    method: "post",
    data: parameter,
  });
}

export function updateCategory(parameter) {
  return request({
    url: "/category/updateCategory",
    method: "post",
    data: parameter,
  });
}

export function getTagsByName(parameter) {
  return request({
    url: "/tag/getAllTagByName",
    method: "get",
    params: parameter,
  });
}

export function addTag(parameter) {
  return request({
    url: "/tag/addTag",
    method: "post",
    data: parameter,
  });
}

export function updateTag(parameter) {
  return request({
    url: "/tag/updateTag",
    method: "post",
    data: parameter,
  });
}

export function deleteTag(parameter) {
  return request({
    url: "/tag/deleteTag",
    method: "delete",
    params: parameter,
  });
}

export function getAllTag() {
  return request({
    url: "/tag/getAllTag",
    method: "get",
  });
}

export function getCategoryById(id) {
  return request({
    url: "/category/getCategoryById",
    method: "get",
    params: id,
  });
}

export function getTagById(id) {
  return request({
    url: "/tag/getTagById",
    method: "get",
    params: id,
  });
}

export function viewArticle(id) {
  return request({
    url: `/article/view`,
    method: "get",
    params: { id: id },
  });
}

export function getCommentsByArticle(id) {
  return request({
    url: `/comment/getCommentByArtId`,
    method: "get",
    params: { id: id },
  });
}

export function publishComment(comment) {
  return request({
    url: "/comment/publishComment",
    method: "post",
    data: comment,
  });
}

export function deleteComment(id) {
  return request({
    url: "/comment/deleteComment",
    method: "get",
    params: { id: id },
  });
}

export function upload(formdata) {
  return request({
    headers: { "Content-Type": "multipart/form-data" },
    url: "/upload/picture",
    method: "post",
    data: formdata,
  });
}

export function listArchives() {
  return request({
    url: "/article/archives",
    method: "get",
  });
}

export function deleteArticle(parameter) {
  return request({
    url: "/article/deleteArticle",
    method: "delete",
    params: parameter,
  });
}

export function deleteCategory(parameter) {
  return request({
    url: "/category/deleteCategory",
    method: "delete",
    params: parameter,
  });
}

export function getUserInfoByToken() {
  return request({
    url: "/user/getUserInfo",
    method: "get",
  });
}

export function updateUser(parameter) {
  return request({
    url: "/user/updateUser",
    method: "post",
    data: parameter,
  });
}

export function uploadAvatar() {
  return request({
    url: "upload/avatar",
    method: "post",
  });
}

//获取用户的登录日志
export function getLog(parameter) {
  return request({
    url: "/log/userLog",
    method: "get",
    params: parameter,
  });
}

//获取用户的操作日志
export function getSystemLog(parameter) {
  return request({
    url: "/log/systemLog",
    method: "get",
    params: parameter,
  });
}

//删除系统日志
export function deleteSystemLog(parameter) {
  return request({
    url: "/log/delete",
    method: "post",
    data: parameter,
  });
}

//修改密码
export function updatePass(parameter) {
  return request({
    url: "/user/updatePwd",
    method: "post",
    data: parameter,
  });
}

export function userTotal() {
  return request({
    url: "/user/userTotal",
    method: "get",
  });
}

export function articleTotal() {
  return request({
    url: "/article/articleTotal",
    method: "get",
  });
}
export function categoryTotal() {
  return request({
    url: "/category/categoryTotal",
    method: "get",
  });
}

export function tagTotal() {
  return request({
    url: "/tag/tagTotal",
    method: "get",
  });
}

export function getUsersByName(parameter) {
  return request({
    url: "/user/getAllUserByName",
    method: "get",
    params: parameter,
  });
}

export function addUser(parameter) {
  return request({
    url: "/user/addUser",
    method: "post",
    data: parameter,
  });
}

export function deleteUser(parameter) {
  return request({
    url: "/user/deleteUser",
    method: "delete",
    params: parameter,
  });
}
